package com.koron.ticket.utils;

import cn.hutool.core.collection.CollUtil;
import com.koron.bean.system.staff.vo.EamUser;
import com.koron.ticket.operation.bean.excelbean.OperationFactoryTemplate;
import com.koron.ticket.operation.bean.excelbean.OperationStepTemplate;
import com.koron.ticket.operation.bean.excelbean.OperationStepcChildrenTemplate;
import com.koron.ticket.power.bean.PowerBean;
import com.koron.ticket.power.bean.TicketNodeBean;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

import static com.koron.ticket.work.enums.TicketStatus.*;

@Slf4j
public class InitData {


    /**
     * 初始话操作步骤模板数据
     *
     * @param eamUser
     * @param templateslist
     */
    public static void InitStepData(EamUser eamUser, List<OperationStepTemplate> templateslist) {
        OperationStepTemplate templates = new OperationStepTemplate();

        //主步骤一
        templates.setSort(1);
        //子步骤
        List<OperationStepcChildrenTemplate> childrenlist = getOperationStepcChildrenTemplates(eamUser, 3);
        templates.setChildren(childrenlist);
        templateslist.add(templates);


        //主步骤二
        OperationStepTemplate templatesTwo = new OperationStepTemplate();
        templatesTwo.setSort(2);
        List<OperationStepcChildrenTemplate> childrenlistTwo = getOperationStepcChildrenTemplates(eamUser, 2);
        templatesTwo.setChildren(childrenlistTwo);
        templateslist.add(templatesTwo);

        OperationStepTemplate templatesThre = new OperationStepTemplate();
        templatesThre.setSort(3);
        templateslist.add(templatesThre);

        OperationStepTemplate templatesFour = new OperationStepTemplate();
        templatesFour.setSort(4);
        templateslist.add(templatesFour);

//        OperationStepTemplate tips = new OperationStepTemplate();
//        tips.setItem("按实际情况，按格式覆盖所上步骤");
//        templateslist.add(tips);
    }

    /**
     * 操作子步骤
     *
     * @param eamUser
     * @return
     */
    private static List<OperationStepcChildrenTemplate> getOperationStepcChildrenTemplates(EamUser eamUser, int num) {
        List<OperationStepcChildrenTemplate> childrenlist = new ArrayList<>();
        log.info("操作用户：{}",eamUser.getName());
        for (int i = 1; i <= num; i++) {
            OperationStepcChildrenTemplate childrenTemplat = new OperationStepcChildrenTemplate();
            childrenTemplat.setDeptName(eamUser.getDeptName());
            childrenTemplat.setItem("操作子步骤 " + i + " 具体内容");
            childrenlist.add(childrenTemplat);
        }
        return childrenlist;
    }


    /**
     * 厂站操作步骤
     *
     * @param eamUser
     * @return
     */
    public static List<OperationFactoryTemplate> getChangZhanTemplates(EamUser eamUser, int num) {
        List<OperationFactoryTemplate> factorylist = new ArrayList<>();
        for (int i = 1; i <= num; i++) {
            OperationFactoryTemplate factoryTele = new OperationFactoryTemplate();
            factoryTele.setItem("操作步骤 " + i + " 具体内容");
//            childrenTemplat.setSort(i);
            if (i == num) {
                factoryTele.setItem("按实际情况，按格式覆盖所上步骤");
            }
            factorylist.add(factoryTele);
        }
        return factorylist;
    }


    /**
     * 初始化工作票基础权限集合
     *
     * @return
     */
    public static List<PowerBean> initBasePower(Boolean unitBoo, Boolean createByUnitBoo, Boolean curnodeuserBoo) {
        PowerBean save = new PowerBean("保存", "save", true);
        PowerBean commit = new PowerBean("提交", "commit", true);
        PowerBean preview = new PowerBean("预览", "preview", false);
        PowerBean change = new PowerBean("变更", "change", true);
        PowerBean operationTicket = new PowerBean("申请操作票", "operationTicket", true);
        PowerBean delete = new PowerBean("删除", "delete", true);
        PowerBean note = new PowerBean("备注", "note", true);
        PowerBean reject = new PowerBean("操作记录", "record", false);
        PowerBean process = new PowerBean("查看流程", "process", false);
        if (curnodeuserBoo) {
            save.setIsPower(false);
            commit.setIsPower(false);
        }
        if (unitBoo || createByUnitBoo) {
            note.setIsPower(false);
        }
        return CollUtil.newArrayList(save, commit, preview, change, operationTicket, delete, note, reject, process);
    }

    /**
     * 初始化电气一二机械工作票节点集合
     *
     * @return
     */
    public static List<TicketNodeBean> initGasAndMechanicsNode(Boolean unitBoo, Boolean createByUnitBoo, Boolean curnodeuserBoo) {
        TicketNodeBean write = new TicketNodeBean(WRITE.getName(), WRITE.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//填写
        TicketNodeBean sign = new TicketNodeBean(SIGN.getName(), SIGN.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待签发
        TicketNodeBean countersign = new TicketNodeBean(COUNTERSIGN.getName(), COUNTERSIGN.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待会签
        TicketNodeBean accept = new TicketNodeBean(ACCEPT.getName(), ACCEPT.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待接受
        TicketNodeBean permit = new TicketNodeBean(PERMIT.getName(), PERMIT.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待许可
        TicketNodeBean work_end = new TicketNodeBean(WORK_END.getName(), WORK_END.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//工作待终结
        TicketNodeBean ticket_end = new TicketNodeBean(TICKET_END.getName(), TICKET_END.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//工作票待终结
        TicketNodeBean archived = new TicketNodeBean(ARCHIVED.getName(), ARCHIVED.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//已归档
        return CollUtil.newArrayList(write, sign, countersign, accept, permit, work_end, ticket_end, archived);
    }


    /**
     * 初始化第三种工作票节点集合
     *
     * @return
     */
    public static List<TicketNodeBean> initThirdicsNode(Boolean unitBoo, Boolean createByUnitBoo, Boolean curnodeuserBoo) {
        TicketNodeBean write = new TicketNodeBean(WRITE.getName(), WRITE.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//填写
        TicketNodeBean permit = new TicketNodeBean(PERMIT.getName(), PERMIT.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待许可
        TicketNodeBean ticket_end = new TicketNodeBean(TICKET_END.getName(), TICKET_END.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//工作票待终结
        TicketNodeBean archived = new TicketNodeBean(ARCHIVED.getName(), ARCHIVED.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//已归档
        return CollUtil.newArrayList(write, permit, ticket_end, archived);
    }

    /**
     * 初始化二级动火节点集合
     *
     * @return
     */
    public static List<TicketNodeBean> initSecondeLevelNode(Boolean unitBoo, Boolean createByUnitBoo, Boolean curnodeuserBoo) {
        TicketNodeBean write = new TicketNodeBean(WRITE.getName(), WRITE.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//填写
        TicketNodeBean sign = new TicketNodeBean(SIGN.getName(), SIGN.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待签发
        TicketNodeBean countersign = new TicketNodeBean(COUNTERSIGN.getName(), COUNTERSIGN.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待会签
        TicketNodeBean accept = new TicketNodeBean(ACCEPT.getName(), ACCEPT.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待接受
        TicketNodeBean permit = new TicketNodeBean(PERMIT.getName(), PERMIT.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待许可
        TicketNodeBean work_end = new TicketNodeBean(WORK_END.getName(), WORK_END.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//工作待终结
        TicketNodeBean archived = new TicketNodeBean(ARCHIVED.getName(), ARCHIVED.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//已归档
        return CollUtil.newArrayList(write, sign, countersign, accept, permit, work_end, archived);
    }

    /**
     * 初始化电力线路一二种工作票节点集合
     *
     * @return
     */
    public static List<TicketNodeBean> initPowerLinNode(Boolean unitBoo, Boolean createByUnitBoo, Boolean curnodeuserBoo) {
        TicketNodeBean write = new TicketNodeBean(WRITE.getName(), WRITE.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//填写
        TicketNodeBean sign = new TicketNodeBean(SIGN.getName(), SIGN.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待签发
        TicketNodeBean countersign = new TicketNodeBean(COUNTERSIGN.getName(), COUNTERSIGN.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待会签（线路第二种没有）
        TicketNodeBean accept = new TicketNodeBean(ACCEPT.getName(), ACCEPT.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待接受
        TicketNodeBean permit = new TicketNodeBean(PERMIT.getName(), PERMIT.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待许可（线路第二种没有）
        TicketNodeBean work_end = new TicketNodeBean(WORK_END.getName(), WORK_END.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//工作待终结
        TicketNodeBean ticket_end = new TicketNodeBean(TICKET_END.getName(), TICKET_END.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//工作票待终结
        TicketNodeBean archived = new TicketNodeBean(ARCHIVED.getName(), ARCHIVED.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//已归档
        return CollUtil.newArrayList(write, sign, countersign, accept, permit, work_end, ticket_end, archived);
    }


    public static List<TicketNodeBean> initZsjBidSectionSecondNode(Boolean unitBoo, Boolean createByUnitBoo, Boolean curnodeuserBoo) {
        TicketNodeBean write = new TicketNodeBean(WRITE.getName(), WRITE.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//填写
        TicketNodeBean permit = new TicketNodeBean(PERMIT.getName(), PERMIT.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//待许可（线路第二种没有）
        TicketNodeBean work_end = new TicketNodeBean(WORK_END.getName(), WORK_END.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//工作待终结
        TicketNodeBean archived = new TicketNodeBean(ARCHIVED.getName(), ARCHIVED.getStatus(), initBasePower(unitBoo, createByUnitBoo, curnodeuserBoo));//已归档
        return CollUtil.newArrayList(write, permit, work_end, archived);
    }

}
